package rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;

import observer.ObserverRemotoCPR;
import observer.ObserverRemotoOF;

public abstract class ModeloRemoto extends UnicastRemoteObject {

	private static final long serialVersionUID = 1L;
	private ArrayList<ObserverRemotoCPR> observersCPR = new ArrayList<ObserverRemotoCPR>();
	private ArrayList<ObserverRemotoOF> observersOF = new ArrayList<ObserverRemotoOF>();

	protected ModeloRemoto() throws RemoteException {
		super();

	}

	public void addObserverRemotoCPR(ObserverRemotoCPR observer)
			throws RemoteException {
		observersCPR.add(observer);
	}

	public void removeObserverRemotoCPR(ObserverRemotoCPR observer)
			throws RemoteException {
		observersCPR.remove(observer);
	}

	public void notifyObserverRemotoCPR() throws RemoteException {
		for (Iterator<ObserverRemotoCPR> i = observersCPR.iterator(); i
				.hasNext();) {
			i.next().update();
		}
	}

	public void addObserverRemotoOF(ObserverRemotoOF observer)
			throws RemoteException {
		observersOF.add(observer);
	}

	public void removeObserverRemotoOF(ObserverRemotoOF observer)
			throws RemoteException {
		observersOF.remove(observer);
	}

	public void notifyObserverRemotoOF() throws RemoteException {
		for (Iterator<ObserverRemotoOF> i = observersOF.iterator(); i.hasNext();) {
			i.next().update();
		}
	}
}
